<?php
include_once 'field.class.php';

class field_style extends field
{
    public $error;
    protected $fieldname = '样式';

    function get_data($data)
    {
        $return = '';
        if(isset($data['color']))
        {
            $return .= $data['color'];
        }
        if(isset($data['bold']))
        {
            $return .= ' ' . $data['bold'];
        }
        return $return;
    }
    
    function create_form($value = '')
    {
        $style = $this->get_value($value);
        
        $field = $this->field_data['field'];
        $form = "<select id='data_{$field}_color' name='data[$field][color]'>";
        $form .= "<option value='' style='' >颜色</option>";
        $form .= "<option value='color:#000000;' style='background-color:#000000;' ></option>";
        $form .= "<option value='color:#FFFFFF;' style='background-color:#FFFFFF;' ></option>";
        $form .= "<option value='color:#008000;' style='background-color:#008000;' ></option>";
        $form .= "<option value='color:#800000;' style='background-color:#800000;' ></option>";
        $form .= "<option value='color:#808000;' style='background-color:#808000;' ></option>";
        $form .= "<option value='color:#000080;' style='background-color:#000080;' ></option>";
        $form .= "<option value='color:#800080;' style='background-color:#800080;' ></option>";
        $form .= "<option value='color:#808080;' style='background-color:#808080;' ></option>";
        $form .= "<option value='color:#FFFF00;' style='background-color:#FFFF00;' ></option>";
        $form .= "<option value='color:#00FF00;' style='background-color:#00FF00;' ></option>";
        $form .= "<option value='color:#00FFFF;' style='background-color:#00FFFF;' ></option>";
        $form .= "<option value='color:#FF00FF;' style='background-color:#FF00FF;' ></option>";
        $form .= "<option value='color:#FF0000;' style='background-color:#FF0000;' ></option>";
        $form .= "<option value='color:#0000FF;' style='background-color:#0000FF;' ></option>";
        $form .= "<option value='color:#008080;' style='background-color:#008080;' ></option>";
        $form .= "</select> ";
        $form .= "<script>$('#data_{$field}_color').val('{$style['color']}')</script>";
        $form .= form::check_yesno("data[$field][bold]", "data_{$field}_bold", '加粗', 'font-weight:bold;', '', $style['bold']);
        return $form;
    }

    function get_value($data)
    {
        $return = array();
        $color = strstr($data, 'color:');
        $return['color'] = empty($color) ? '' : substr($color, 0, 14);
        $color = strstr($data, 'font-weight:');
        $return['bold'] = empty($color) ? '' : 'font-weight:bold;';
        return $return;
    }
}
?>